#Boa:Frame:Frame_EditUsuario

import wx
from Class_GerenciadorUsuario import *

def create(parent, Usuario):
    return Frame_EditUsuario(parent, Usuario)

[wxID_FRAME_EDITUSUARIO, wxID_FRAME_EDITUSUARIOBUTTON1, 
 wxID_FRAME_EDITUSUARIOBUTTON2, wxID_FRAME_EDITUSUARIOBUTTON3, 
 wxID_FRAME_EDITUSUARIODATEPICKERCTRL1, wxID_FRAME_EDITUSUARIOSTATICBOX1, 
 wxID_FRAME_EDITUSUARIOSTATICBOX2, wxID_FRAME_EDITUSUARIOSTATICBOX3, 
 wxID_FRAME_EDITUSUARIOSTATICBOX4, wxID_FRAME_EDITUSUARIOSTATICTEXT1, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT10, wxID_FRAME_EDITUSUARIOSTATICTEXT11, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT12, wxID_FRAME_EDITUSUARIOSTATICTEXT13, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT15, wxID_FRAME_EDITUSUARIOSTATICTEXT16, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT17, wxID_FRAME_EDITUSUARIOSTATICTEXT18, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT2, wxID_FRAME_EDITUSUARIOSTATICTEXT3, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT4, wxID_FRAME_EDITUSUARIOSTATICTEXT5, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT6, wxID_FRAME_EDITUSUARIOSTATICTEXT7, 
 wxID_FRAME_EDITUSUARIOSTATICTEXT8, wxID_FRAME_EDITUSUARIOSTATICTEXT9, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL1, wxID_FRAME_EDITUSUARIOTEXTCTRL10, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL11, wxID_FRAME_EDITUSUARIOTEXTCTRL12, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL14, wxID_FRAME_EDITUSUARIOTEXTCTRL15, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL16, wxID_FRAME_EDITUSUARIOTEXTCTRL17, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL2, wxID_FRAME_EDITUSUARIOTEXTCTRL3, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL4, wxID_FRAME_EDITUSUARIOTEXTCTRL5, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL6, wxID_FRAME_EDITUSUARIOTEXTCTRL7, 
 wxID_FRAME_EDITUSUARIOTEXTCTRL8, wxID_FRAME_EDITUSUARIOTEXTCTRL9, 
 wxID_FRAME_EDITUSUARIOWINDOW1, wxID_FRAME_EDITUSUARIOWINDOW2, 
 wxID_FRAME_EDITUSUARIOWINDOW3, wxID_FRAME_EDITUSUARIOWINDOW4, 
] = [wx.NewId() for _init_ctrls in range(46)]

class Frame_EditUsuario(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME_EDITUSUARIO,
              name=u'Frame_EditUsuario', parent=prnt, pos=wx.Point(433, 16),
              size=wx.Size(719, 692), style=wx.DEFAULT_FRAME_STYLE,
              title=u'Frame_EditUsuario')
        self.SetClientSize(wx.Size(703, 654))
        self.SetBackgroundColour(wx.Colour(228, 228, 228))

        self.window1 = wx.Window(id=wxID_FRAME_EDITUSUARIOWINDOW1,
              name='window1', parent=self, pos=wx.Point(24, 24),
              size=wx.Size(296, 188), style=wx.TAB_TRAVERSAL)

        self.window2 = wx.Window(id=wxID_FRAME_EDITUSUARIOWINDOW2,
              name='window2', parent=self, pos=wx.Point(24, 240),
              size=wx.Size(296, 392), style=wx.TAB_TRAVERSAL)

        self.window3 = wx.Window(id=wxID_FRAME_EDITUSUARIOWINDOW3,
              name='window3', parent=self, pos=wx.Point(352, 224),
              size=wx.Size(320, 280), style=wx.TAB_TRAVERSAL)

        self.staticBox1 = wx.StaticBox(id=wxID_FRAME_EDITUSUARIOSTATICBOX1,
              label=u'Dados Pessoais', name='staticBox1', parent=self.window1,
              pos=wx.Point(8, 8), size=wx.Size(280, 168), style=0)
        self.staticBox1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticBox2 = wx.StaticBox(id=wxID_FRAME_EDITUSUARIOSTATICBOX2,
              label=u'Endere\xe7o', name='staticBox2', parent=self.window2,
              pos=wx.Point(8, 8), size=wx.Size(280, 368), style=0)
        self.staticBox2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticBox4 = wx.StaticBox(id=wxID_FRAME_EDITUSUARIOSTATICBOX4,
              label=u'Contato', name='staticBox4', parent=self.window3,
              pos=wx.Point(16, 8), size=wx.Size(288, 256), style=0)
        self.staticBox4.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL1,
              name='textCtrl1', parent=self.window1, pos=wx.Point(168, 40),
              size=wx.Size(100, 24), style=0, value=u'')
        self.textCtrl1.Enable(False)

        self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL2,
              name='textCtrl2', parent=self.window1, pos=wx.Point(168, 72),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl3 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL3,
              name='textCtrl3', parent=self.window1, pos=wx.Point(168, 104),
              size=wx.Size(100, 24), style=0, value=u'')

        self.staticText1 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT1,
              label=u'ID', name='staticText1', parent=self.window1,
              pos=wx.Point(128, 40), size=wx.Size(12, 16), style=0)
        self.staticText1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText2 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT2,
              label=u'Nome*', name='staticText2', parent=self.window1,
              pos=wx.Point(104, 72), size=wx.Size(41, 16), style=0)
        self.staticText2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText3 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT3,
              label=u'Sobrenome*', name='staticText3', parent=self.window1,
              pos=wx.Point(72, 104), size=wx.Size(74, 16), style=0)
        self.staticText3.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.datePickerCtrl1 = wx.DatePickerCtrl(id=wxID_FRAME_EDITUSUARIODATEPICKERCTRL1,
              name='datePickerCtrl1', parent=self.window1, pos=wx.Point(168,
              136), size=wx.Size(96, 24), style=wx.DP_SHOWCENTURY)

        self.staticText4 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT4,
              label=u'Data de Nascimento*', name='staticText4',
              parent=self.window1, pos=wx.Point(24, 136), size=wx.Size(122, 16),
              style=0)
        self.staticText4.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText5 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT5,
              label=u'CEP*', name='staticText5', parent=self.window2,
              pos=wx.Point(96, 40), size=wx.Size(30, 16), style=0)
        self.staticText5.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText6 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT6,
              label=u'Logradouro*', name='staticText6', parent=self.window2,
              pos=wx.Point(56, 80), size=wx.Size(73, 16), style=0)
        self.staticText6.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText7 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT7,
              label=u'N\xfamero', name='staticText7', parent=self.window2,
              pos=wx.Point(72, 120), size=wx.Size(45, 16), style=0)
        self.staticText7.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText8 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT8,
              label=u'Complemento', name='staticText8', parent=self.window2,
              pos=wx.Point(40, 160), size=wx.Size(79, 16), style=0)
        self.staticText8.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText9 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT9,
              label=u'Bairro*', name='staticText9', parent=self.window2,
              pos=wx.Point(88, 200), size=wx.Size(42, 16), style=0)
        self.staticText9.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText10 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT10,
              label=u'Cidade*', name='staticText10', parent=self.window2,
              pos=wx.Point(80, 240), size=wx.Size(47, 16), style=0)
        self.staticText10.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText11 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT11,
              label=u'Estado*', name='staticText11', parent=self.window2,
              pos=wx.Point(80, 280), size=wx.Size(46, 16), style=0)
        self.staticText11.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText12 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT12,
              label=u'Pa\xeds*', name='staticText12', parent=self.window2,
              pos=wx.Point(96, 320), size=wx.Size(31, 16), style=0)
        self.staticText12.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.textCtrl4 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL4,
              name='textCtrl4', parent=self.window2, pos=wx.Point(136, 40),
              size=wx.Size(88, 24), style=0, value=u'')

        self.textCtrl5 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL5,
              name='textCtrl5', parent=self.window2, pos=wx.Point(136, 80),
              size=wx.Size(144, 24), style=0, value=u'')

        self.textCtrl6 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL6,
              name='textCtrl6', parent=self.window2, pos=wx.Point(136, 120),
              size=wx.Size(56, 24), style=0, value=u'')

        self.textCtrl7 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL7,
              name='textCtrl7', parent=self.window2, pos=wx.Point(136, 160),
              size=wx.Size(144, 24), style=0, value=u'')

        self.textCtrl8 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL8,
              name='textCtrl8', parent=self.window2, pos=wx.Point(136, 200),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl9 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL9,
              name='textCtrl9', parent=self.window2, pos=wx.Point(136, 240),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl10 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL10,
              name='textCtrl10', parent=self.window2, pos=wx.Point(136, 280),
              size=wx.Size(112, 24), style=0, value=u'')

        self.textCtrl11 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL11,
              name='textCtrl11', parent=self.window2, pos=wx.Point(136, 320),
              size=wx.Size(128, 24), style=0, value=u'')

        self.window4 = wx.Window(id=wxID_FRAME_EDITUSUARIOWINDOW4,
              name='window4', parent=self, pos=wx.Point(352, 24),
              size=wx.Size(248, 152), style=wx.TAB_TRAVERSAL)

        self.staticBox3 = wx.StaticBox(id=wxID_FRAME_EDITUSUARIOSTATICBOX3,
              label=u'Acesso', name='staticBox3', parent=self.window4,
              pos=wx.Point(8, 8), size=wx.Size(232, 136), style=0)
        self.staticBox3.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.textCtrl12 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL12,
              name='textCtrl12', parent=self.window4, pos=wx.Point(104, 40),
              size=wx.Size(112, 24), style=0, value=u'')

        self.staticText13 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT13,
              label=u'Login*', name='staticText13', parent=self.window4,
              pos=wx.Point(48, 40), size=wx.Size(38, 16), style=0)
        self.staticText13.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.textCtrl14 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL14,
              name='textCtrl14', parent=self.window3, pos=wx.Point(160, 96),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl15 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL15,
              name='textCtrl15', parent=self.window3, pos=wx.Point(160, 144),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl16 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL16,
              name='textCtrl16', parent=self.window3, pos=wx.Point(160, 192),
              size=wx.Size(100, 24), style=0, value=u'')

        self.textCtrl17 = wx.TextCtrl(id=wxID_FRAME_EDITUSUARIOTEXTCTRL17,
              name='textCtrl17', parent=self.window3, pos=wx.Point(160, 48),
              size=wx.Size(100, 24), style=0, value=u'')

        self.staticText15 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT15,
              label=u'Email*', name='staticText15', parent=self.window3,
              pos=wx.Point(96, 48), size=wx.Size(39, 16), style=0)
        self.staticText15.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText16 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT16,
              label=u'Telefone 1*', name='staticText16', parent=self.window3,
              pos=wx.Point(64, 96), size=wx.Size(70, 16), style=0)
        self.staticText16.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText17 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT17,
              label=u'Telefone 2', name='staticText17', parent=self.window3,
              pos=wx.Point(64, 144), size=wx.Size(62, 16), style=0)
        self.staticText17.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.staticText18 = wx.StaticText(id=wxID_FRAME_EDITUSUARIOSTATICTEXT18,
              label=u'Telefone 3', name='staticText18', parent=self.window3,
              pos=wx.Point(64, 192), size=wx.Size(62, 16), style=0)
        self.staticText18.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.button1 = wx.Button(id=wxID_FRAME_EDITUSUARIOBUTTON1,
              label=u'Salvar', name='button1', parent=self, pos=wx.Point(448,
              528), size=wx.Size(136, 40), style=0)
        self.button1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME_EDITUSUARIOBUTTON1)

        self.button2 = wx.Button(id=wxID_FRAME_EDITUSUARIOBUTTON2,
              label=u'Cancelar', name='button2', parent=self, pos=wx.Point(448,
              584), size=wx.Size(136, 40), style=0)
        self.button2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_FRAME_EDITUSUARIOBUTTON2)

        self.button3 = wx.Button(id=wxID_FRAME_EDITUSUARIOBUTTON3,
              label=u'Alterar Senha', name='button3', parent=self.window4,
              pos=wx.Point(80, 88), size=wx.Size(104, 32), style=0)
        self.button3.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))
        self.button3.Bind(wx.EVT_BUTTON, self.OnButton3Button,
              id=wxID_FRAME_EDITUSUARIOBUTTON3)

    def __init__(self, parent, Usuario):
        self._init_ctrls(parent)
        self.usuario = Usuario
        self.senha = self.usuario.GetSenha()
        
        #Carrega os dados do Objeto Usuario para o Frame
        
        #Dados Pessoais
        self.textCtrl1.SetValue(str(Usuario.GetID()))
        self.textCtrl2.SetValue(Usuario.GetNome())
        self.textCtrl3.SetValue(Usuario.GetSobrenome())

        
        #Endereco
        self.textCtrl4.SetValue(Usuario.GetEndereco().GetCEP())
        self.textCtrl5.SetValue(Usuario.GetEndereco().GetLogradouro()) 
        self.textCtrl6.SetValue(str(Usuario.GetEndereco().GetNumero()))
        self.textCtrl7.SetValue(Usuario.GetEndereco().GetComplemento()) 
        self.textCtrl8.SetValue(Usuario.GetEndereco().GetBairro()) 
        self.textCtrl9.SetValue(Usuario.GetEndereco().GetCidade()) 
        self.textCtrl10.SetValue(Usuario.GetEndereco().GetEstado()) 
        self.textCtrl11.SetValue(Usuario.GetEndereco().GetPais()) 
        
        #Acesso
        self.textCtrl12.SetValue(Usuario.GetLogin())
        
        #Contato
        self.textCtrl17.SetValue(Usuario.GetContato().GetEmail())
        self.textCtrl14.SetValue(Usuario.GetContato().GetTelefone1())
        self.textCtrl15.SetValue(Usuario.GetContato().GetTelefone2())
        self.textCtrl16.SetValue(Usuario.GetContato().GetTelefone3())
    
    #botao "Cancelar"
    def OnButton2Button(self, event):
        import Frame_PaginaUsuario
        usuario = self.CriarUsuario()
        Frame_PaginaUsuario.create(None, usuario).Show()
        self.Close()    
        
    #Botao "Salvar"
    def OnButton1Button(self, event):
        
        G = GerenciadorUsuario()
        
        usuario = self.CriarUsuario()
        dados = G.PesquisarUsuario('Id', usuario.GetID())
        
        IdEndereco = dados[0][4] 
        IdContato = dados[0][5]
        IdAcesso = dados[0][6]
        
        
        confirmacao = G.EditarUsuario(usuario, IdAcesso, IdContato, IdEndereco)
        #if confirmacao == True:
        m = "Atualizacao do Perfil Realizado com Sucesso!"
        t = "Cadastro de Usuario"
        wx.MessageBox(m,t,wx.OK)
            
        import Frame_PaginaUsuario
        usuario = self.CriarUsuario()
        Frame_PaginaUsuario.create(None, usuario).Show()
        self.Close()

    #Botao "Editar Senha"
    def OnButton3Button(self, event):
    
        import Dialog_EditarSenha
        self.tela = Dialog_EditarSenha.create(self, self.usuario.GetSenha())
        self.tela.ShowModal()
        self.senha = self.tela.NovaSenha
        
        
    #Funcao para criar um objeto usuario com os dados dos textCtrl    
    def CriarUsuario(self):
        #Contato
        Email = self.textCtrl17.GetValue()
        Telefone1 = self.textCtrl14.GetValue()
        Telefone2 = self.textCtrl15.GetValue()
        Telefone3 = self.textCtrl16.GetValue()
        contato = Contato(Telefone1, Telefone2, Telefone3, Email)
        
        #Endereco
        CEP = self.textCtrl4.GetValue()
        Logradouro = self.textCtrl5.GetValue()
        Numero = self.textCtrl6.GetValue()
        Complemento = self.textCtrl7.GetValue()
        Bairro = self.textCtrl8.GetValue()
        Cidade = self.textCtrl9.GetValue()
        Estado = self.textCtrl10.GetValue()
        Pais = self.textCtrl11.GetValue()
        endereco = Endereco(Logradouro, Numero, Complemento, Bairro, Cidade, Estado, Pais, CEP)
    
        #Usuario
        ID = self.textCtrl1.GetValue()
        Nome = self.textCtrl2.GetValue()
        Sobrenome = self.textCtrl3.GetValue()
        DataNasc = (self.datePickerCtrl1.GetValue())
        Login = self.textCtrl12.GetValue()
        Senha = self.senha
        
        #Pegar data Nascimento
        Ano = DataNasc.GetYear()
        Mes = DataNasc.GetMonth()
        Dia = DataNasc.GetDay()
        Data = '%s-%s-%s'%(Ano, Mes, Dia)
        
        usuario = Usuario(Nome, Sobrenome, Data, Login, Senha, contato, endereco)
        usuario.SetID(ID)
        
        return usuario
